package com.zbf.entity;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;


/**
 * @author: LCG
 * 作者: LCG
 * 日期: 2021/6/23  16:12
 * 描述:
 */
@Converter(autoApply = true)
public class MyUserConveter implements AttributeConverter<SexEnum,Integer> {

    @Override
    public Integer convertToDatabaseColumn(SexEnum sexEnum) {
        return sexEnum.getCode();
    }

    @Override
    public SexEnum convertToEntityAttribute(Integer integer) {
        for (SexEnum sexEnum : SexEnum.values()) {
            if(sexEnum.getCode().intValue()==integer){
               return sexEnum;
            }
        }
        return null;
    }
}
